package com.example.administrator.mobliesafe;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.example.administrator.mobilesafe.utils.BaseSetupAcitivity;

public class Setup4Activity extends BaseSetupAcitivity {
    private Button bt_srtup4_pre;
    private Button bt_srtup4_next;
    private CheckBox cb_protect;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setup4);
        cb_protect = (CheckBox) findViewById(R.id.cb_protect);
        sharedPreferences = getSharedPreferences("config",MODE_PRIVATE);
        bt_srtup4_next = (Button) findViewById(R.id.bt_setup2_next);
        bt_srtup4_pre = (Button) findViewById(R.id.bt_setup2_pre);
        bt_srtup4_pre.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pre(v);
            }
        });
        bt_srtup4_next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                next(v);
            }
        });

        boolean  protecting = sharedPreferences.getBoolean("protecting", false);
        if(protecting){
            //手机防盗已经开启了
            cb_protect.setText("手机防盗已经开启");
            cb_protect.setChecked(true);
        }else{
            //手机防盗没有开启
            cb_protect.setText("手机防盗没有开启");
            cb_protect.setChecked(false);
        }
        cb_protect.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    cb_protect.setText("手机防盗已经开启");
                }else{
                    cb_protect.setText("手机防盗没有开启");
                }

                //保存选择的状态
                SharedPreferences.Editor editor = sharedPreferences.edit();
                editor.putBoolean("protecting", isChecked);
                editor.commit();
            }
        });
    }

    @Override
    public void showPre() {
        Intent intent = new Intent(Setup4Activity.this,Setup3Activity.class);
        startActivity(intent);
        finish();
        overridePendingTransition(R.anim.tran_in, R.anim.tran_out);
    }

    @Override
    public void showNext() {
        Intent intent = new Intent(Setup4Activity.this,LostFoundActivity.class);
        startActivity(intent);
        finish();
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean("isSetup", true);
        editor.commit();
        overridePendingTransition(R.anim.tran_out, R.anim.tran_in);
    }


}
